<table id="manage_hotel" data-options="fit:true"></table>
<script>
$(function(){
	$.ajax({
	    url: "../json/LocalInfo_getLids",    //请求的url地址
	    dataType: "json",   //返回格式为json
	    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
	    type: "POST", 
	    success: function(data) {
	    	var info="";
	    	for(var i=0;i<data.rows.length;i++){
	    		info+="<option value="+data.rows[i].lid+">"+data.rows[i].lname+"</option>";
	    	}
	    	$("#hotel_lid").append(info);
	    }
	});
	
	$('#manage_hotel').datagrid({
		url:'../json/Hotel_getHotelList',
		loadMsg:'数据加载中...',
		fitColumns:true,
		rownumbers:true,
		striped:true,
		sortName:'hid',
		sortOrder:'asc',
		remoteSort:false,
		columns:[[
			{field:'hids',title:'',width:100,align:'center',checkbox:true},
			{field:'hid',title:'宾馆编号',width:30,align:'center',sortable:true},
			{field:'lid',title:'关联景区',width:30,align:'center'}, 
			{field:'hname',title:'宾馆名称',width:100,align:'center'}, 
			{field:'htype',title:'宾馆类型',width:50,align:'center'},
			{field:'haddr',title:'宾馆地址',width:100,align:'center'},
			{field:'hprice',title:'宾馆均价',width:30,align:'center'},
			{field:'htel',title:'联系方式',width:100,align:'center'}
		]],
		toolbar: [{
			iconCls: 'icon-add',
			text:'添加',
			handler: function(){
				$("#add_hotel").dialog("open");
			}
		},'-',{
			iconCls: 'icon-edit',
			text:'修改',
			handler: function(){
				getOneHotelInfo();
			}
		}]
	});
});

function addHotelInfo(){
	var hname=$("#hotel_hname").val();
	var htype=$("#hotel_htype").val();
	var htel=$("#hotel_htel").val();
	var haddr=$("#hotel_haddr").val();
	var hprice=$("#hotel_hprice").val();
	var lid=$("#hotel_lid").val();
	$.ajax({
	    url: "../json/Hotel_addHotelInfo",    //请求的url地址
	    dataType: "json",   //返回格式为json
	    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
	    type: "POST",
	    data:{
	    	"hname":hname,
	    	"htype":htype,
	    	"htel":htel,
	    	"haddr":haddr,
	    	"hprice":hprice,
	    	"lid":lid
	    },
	    success: function(data) {
	    	if(parseInt($.trim(data.obj))>=1){
	    		$.messager.show({
					title:'成功提示',
					msg:'添加信息成功！',
					timeout:3000,
					showType:'slide'
				});
	    		$("#add_hotel").dialog("close");
	    		$("#hotel_hname").val("");
	    		$("#hotel_htype").val("");
	    		$("#hotel_htel").val("");
	    		$("#hotel_haddr").val("");
	    		$("#hotel_hprice").val("");
	    		$("#hotel_lid").val("");
				$('#manage_hotel').datagrid("reload");
	    	}else{
	    		$.messager.alert('错误提示','添加信息失败,请稍后重试!','error');
	    	}
	    }
	});
}

function updateHotelInfo(){
	var htel=$("#update_htel").val();
	var hprice=$("#update_hprice").val();
	var hname=$("#update_hname").val();
	$.ajax({
	    url: "../json/Hotel_updateHotelInfo",    //请求的url地址
	    dataType: "json",   //返回格式为json
	    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
	    type: "POST",
	    data:{
	    	"htel":htel,
	    	"hprice":hprice,
	    	"hname":hname
	    },
	    success: function(data) {
	    	if(parseInt($.trim(data.obj))>=1){
	    		$.messager.show({
					title:'成功提示',
					msg:'修改信息成功！',
					timeout:3000,
					showType:'slide'
				});
	    		$("#update_hotel").dialog("close");
	    		$("#update_htel").val("");
	    		$("#update_hprice").val("");
	    		$("#update_hname").val("");
				$('#manage_hotel').datagrid("reload");
	    	}else{
	    		$.messager.alert('错误提示','添加信息失败,请稍后重试!','error');
	    	}
	    }
	});
}

function getOneHotelInfo(){
	var hotels=$('#manage_hotel').datagrid("getSelections");
	if(hotels.length==0){
		$.messager.alert('错误提示','请选择修改的信息!','error');
		return;
	}
	if(hotels.length>1){
		$.messager.alert('错误提示','请逐个修改信息!','error');
		return;
	}
	$("#update_hotel").dialog("open");
	var hid=hotels[0].hid;
	$.ajax({
	    url: "../json/Hotel_getOneHotelInfo",    //请求的url地址
	    dataType: "json",   //返回格式为json
	    async: true, //请求是否异步，默认为异步，这也是ajax重要特性
	    type: "POST",
	    data:{"hid":hid},
	    success: function(data) {
	    	$("#update_htel").val(data.obj.htel);
	    	$("#update_hprice").val(data.obj.hprice);
	    	$("#update_hname").val(data.obj.hname);
	    }
	});
}

</script>
<div id="add_hotel" class="easyui-dialog" title="添加宾馆" style="width:400px;height:350px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label for="hotel_hname">宾馆名称：</label><input type="text" id="hotel_hname">
		<br /> <br /> 
		<label for="hotel_htype">宾馆类型：</label><input type="text" id="hotel_htype">
		<br /> <br />
		<label for="hotel_htel">联系方式：</label><input type="text" id="hotel_htel">
		<br /> <br />
		<label for="hotel_haddr">宾馆地址：</label><input type="text" id="hotel_haddr">
		<br /> <br />
		<label for="hotel_hprice">宾馆均价：</label><input type="text" id="hotel_hprice">
		<br /> <br />
		<label>关联景区：</label>
		<select id="hotel_lid">
			<option value="">请选择关联景区</option>
		</select>
		<br/><br/>
		<input style="padding:5px 25px;" type="button" onclick="addHotelInfo()" value="添加">
	</p>
</div>

<div id="update_hotel" class="easyui-dialog" title="修改宾馆信息" style="width:400px;height:300px;"
	data-options="iconCls:'icon-add',resizable:true,modal:true,closed:true">
	<p style="width:100%;text-align:center;">
		<br /> <br /> 
		<label for="update_hname">宾馆名称：</label><input type="text" id="update_hname" disabled="disabled">
		<br /> <br /> 
		<label for="update_htel">联系方式：</label><input type="text" id="update_htel">
		<br /> <br /> 
		<label for="update_hprice">宾馆均价：</label><input type="text" id="update_hprice">
		<br /> <br /> 
		<input style="padding:5px 25px;" type="button" onclick="updateHotelInfo()" value="修改">
	</p>
</div>

